/**
 * 格式化时间段（ISO字符串数组）为 "YYYY-MM-DD ~ YYYY-MM-DD"
 */
export function formatRange(val: any) {
  if (Array.isArray(val) && val.length === 2 && val[0] && val[1]) {
    const format = (iso: string) => {
      if (!iso) return "";
      const d = new Date(iso);
      if (isNaN(d.getTime())) return "";
      const y = d.getFullYear();
      const m = String(d.getMonth() + 1).padStart(2, "0");
      const day = String(d.getDate()).padStart(2, "0");
      return `${y}-${m}-${day}`;
    };
    return `${format(val[0])} ~ ${format(val[1])}`;
  }
  return "-";
}



/**
 * 判断当前是否在众筹有效期内
 */
export function isInCrowdFundingPeriod(time: string[] | undefined): boolean {
  if (!time || !Array.isArray(time) || time.length !== 2) return false;
  const now = Date.now();
  const start = new Date(time[0]).getTime();
  const end = new Date(time[1]).getTime();
  return now >= start && now <= end;
}